<template>
  <div class="shopping_cart_item_container">
    <div class="shopping_cart_item_checkbox">
      <!-- v-model checked变化了 =====> this.item.checked = checked， -->
      <input type="checkbox" :checked="this.item.checked" ref="checkbox" v-on:change="onChangeStatus"/>
    </div>
    <div class="shopping_cart_item_image">
      <img :src="this.item.item_icon"/>
    </div>
    <div class="shopping_cart_item_info">
      <div class="shopping_cart_item_title">{{this.item.item_name}}</div>
      <div class="shopping_cart_item_price">{{this.item.price}}</div>
      <div>
        <van-stepper v-model="this.item.count"
        v-on:plus="plus"
        v-on:minus="minus"/>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props:{
    item:Object
  },
  data:function(){
    return{
      
    }
  },
  methods:{
    onChangeStatus:function(){
    //  console.log(this.$refs.checkbox.checked)
    //不能直接更改item的状态，因为item在vuex的管理之下，要想更改，需要提交action
    // console.log(this.item)
      var tempItem = {
        item_name:this.item.item_name,
        item_icon:this.item.item_icon,
        id:this.item.id,
        checked:this.$refs.checkbox.checked
      }
      this.$store.dispatch("updateStoreItemChecked",tempItem);
    },
    plus:function(){
       var tempItem = {
        item_name:this.item.item_name,
        item_icon:this.item.item_icon,
        id:this.item.id,
        checked:this.$refs.checkbox.checked,
        count:this.item.count+=1
      }

      this.$store.dispatch("updateStoreItemCount",tempItem)
    },
    minus:function(){
       var tempItem = {
        item_name:this.item.item_name,
        item_icon:this.item.item_icon,
        id:this.item.id,
        checked:this.$refs.checkbox.checked,
        count:this.item.count-=1
      }

      this.$store.dispatch("updateStoreItemCount",tempItem)
    }
  }
}
</script>

<style scoped>
.shopping_cart_item_container
{
  width: 100%;
  height: 220px;
  margin-bottom: 10px;
  border: 1px solid lightgray;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.shopping_cart_item_checkbox
{
  width: 10%;
  height: 220px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.shopping_cart_item_image
{
  width: 40%;
  height: 220px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.shopping_cart_item_image img
{
  width: 120px;
  height: 120px;
}

.shopping_cart_item_info
{
  width: 50%;
  height: 220px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  flex-wrap: wrap;
}

.shopping_cart_item_title{
  width: 100%;
}

.shopping_cart_item_price
{
  width: 100%;
}
</style>